using System.Collections.Generic;
using Newtonsoft.Json.Linq;

namespace WineCellar.Web.Helpers
{
    public class ExtFilter
    {
        /// <summary>
        /// Sets the DataIndex, used internally by the grid
        /// </summary>
        /// <value>The index.</value>
        public string DataIndex { get; set; }

        /// <summary>
        /// Sets the datatype for the filter
        /// </summary>
        /// <value>The width.</value>
        public string DataType { get; set; }


        public IEnumerable<string> Options { get; set; }

        public string JavaScriptString
        {
            get
            {
                JObject jo = new JObject();

                if (!string.IsNullOrEmpty(DataIndex))
                {
                    jo.Add(new JProperty("dataIndex", DataIndex));
                }

                if (!string.IsNullOrEmpty(DataType))
                {
                    jo.Add(new JProperty("type", DataType));
                }

                if (Options != null)
                {
                    var array = new JArray();
                    foreach (var s in Options)
                    {
                        array.Add(s);
                    }
                    jo.Add(new JProperty("options", array));
                }

                return jo.ToString();
            }
        }
    }
}